//
//  Constants.m
//  dgzone
//
//  Created by Benson Zhang on 13-3-27.
//
//

#import "BasicUI.h"




@implementation BasicUI

//- (UIBarButtonItem *)createBtnWithImg:(NSString *)imgName action:(SEL)actionMethod
//{
//    UIImage *keyboardAddImage = [UIImage imageNamed:imgName];
//    UIButton *toggleKeyboardButton = [UIButton buttonWithType:UIButtonTypeCustom];
//    toggleKeyboardButton.bounds = CGRectMake( 0, 0, keyboardAddImage.size.width, keyboardAddImage.size.height );
//    [toggleKeyboardButton addTarget:self action:actionMethod forControlEvents:UIControlEventTouchUpInside];
//    
//    
//    [toggleKeyboardButton setImage:keyboardAddImage forState:UIControlStateNormal];
//    UIBarButtonItem *toggleKeyboardItem = [[UIBarButtonItem alloc] initWithCustomView:toggleKeyboardButton];
//    return toggleKeyboardItem;
//}

- (UIBarButtonItem *)createBtnWithImg:(NSString *)imgName action:(SEL)actionMethod
{
    NSString *btnName = @"返回";
    if ([imgName isEqualToString:@"refresh.png"]){
        btnName = @"刷新";
    }
    UIBarButtonItem *toggleKeyboardItem = [[UIBarButtonItem alloc]initWithTitle:btnName style:UIBarButtonItemStylePlain target:self action:actionMethod];
    return toggleKeyboardItem;
}

-(void)backPage : (UIWebView *) myWebView curUrl:(NSString *) webUrl
{


  if (self.navigationItem.leftBarButtonItem == nil){
            UIBarButtonItem *toggleKeyboardItem = [self createBtnWithImg :@"back_dark.png" action:@selector(backPage)];
        self.navigationItem.leftBarButtonItem = toggleKeyboardItem;
  }
//[self performSelectorOnMainThread:@selector(disableBtn:) withObject:myWebView waitUntilDone:NO];
   
    
    [self performSelector: @selector(disableBtn:) withObject:myWebView afterDelay:0.1 ];

    
}
-(void)disableBtn : (UIWebView *) myWebViewLocal  {
    if (![myWebViewLocal canGoBack] ){
        self.navigationItem.leftBarButtonItem = nil;
    }
}


-(void)refreshThisPage : (UIWebView *) myWebViewLocal  urlFre :(NSString *) urlRefresh
{
    [self performSelector: @selector(disableBtnForRef:) withObject:myWebViewLocal afterDelay:0.02 ];
}
-(void)disableBtnForRef : (UIWebView *) myWebViewLocal  {
    if (![myWebViewLocal canGoBack] ){
        self.navigationItem.leftBarButtonItem = nil;
    } else {
        [myWebViewLocal goBack];
//        NSLog(@"------back---%@",myWebViewLocal.request.URL.absoluteString);
        [self performSelector: @selector(disableBtnForRef:) withObject:myWebViewLocal afterDelay:0.02 ];
    }
}

-(NSString *)getWebUrl: (NSString *) curUrl
{
    return @"http://baidu.com";
    
}



@end
